function Account(id, name, own) {
	this.id = id;
	this.name = name;
	this.own = own;
}

function AccountSource(accounts, showEmptyChoice) {
    this.localdata = accounts;
    this.datatype = "array";
    this.datafields = [
        { name: 'id', type: 'string' },
        { name: 'name', type: 'string' }
    ];
    this.id = 'id';
}

function AccountCombo(div, accounts) {

	this.value = null;
	this.accounts = accounts;
	this.filteredAccounts = accounts;
	this.anyAccount = new Account(-1, "Любой счет", false);

    this.render = function() {
	    var self = this;
	    this.filteredAccounts = this.accounts.slice(0);
	    this.filteredAccounts.splice(0, 0, this.anyAccount);
	    var accountsMap = {};
	    this.filteredAccounts.forEach(function (account) {
		    accountsMap[account.id] = account;
	    });
	    var accountsSource = new AccountSource(this.filteredAccounts, true);
	    var accountsAdapter = new $.jqx.dataAdapter(accountsSource);
        $(div).jqxComboBox({
	        source: accountsAdapter,
	        selectedIndex: 0,
	        displayMember: 'name',
	        valueMember: 'id',
	        autoComplete: true,
	        width: 100
        });
	    this.value = this.anyAccount;

	    $(div).on('select', function(event) {
		    self.value = accountsMap[event.args.item.value];
	    });
    };

	this.select = function (id) {
		var index = -1;
		var count = 0;
		this.filteredAccounts.forEach(function(account) {
			if(account.id === id) {
				index = count;
				return false;
			}
			count++;
		});
		if(index >= 0) {
			$(div).jqxComboBox({ selectedIndex: index });
		}
	};
}